<?php

$oReq = &App::getRequest();
$oTpl = &App::getTemplate();
$oDb = &Database::get();
$oLang = &App::getLanguage();

App::loadClass('Validator');

$iId = $oReq->get('id');

if ( !$iId )
{
	App::gotoUrl('admin');
}

if ( $oReq->get('submit') )
{
	$aPost = $oReq->getArray('val');

	$aQuery = array
	(
		'title' => $aPost['title'],
		'userselect' => $aPost['userselect'],
		'languagecode' => $aPost['languagecode'],
		'charset' => $aPost['charset'],
		'direction' => $aPost['direction'],
	);

	$oDb->update(App::getT('language'), $aQuery, "languageid = '". $iId ."'");

	App::rmCache('language_listing.php');
	App::rmCache('languages_'. $iId .'.php');
	App::gotoUrl('admin.language.edit', array('id' => $iId), App::format('language_updated'), false);
}

$aFields = array
(
	'val[title]'   => array('title' => App::format('language_title'), 'def' => 'required'),
	'val[languagecode]'   => array('title' => App::format('laguage_abb_code'), 'def' => 'required'),
	'val[charset]'   => array('title' => App::format('language_charset'), 'def' => 'required'),
);
$oValidator = &new Validator($aFields, array());

$aItem = $oDb->getRow("SELECT * FROM ". App::getT('language') ." WHERE languageid = '". $iId ."'");

$oTpl->assignSrc('sValMess', $oValidator->makeJsMess());
$oTpl->assignSrc('sValJs', $oValidator->makeJS());
$oTpl->assign(array
(
	'aItem' => (isset($aItem) ? $aItem : ''),
));

?>